from django.shortcuts import render

# Create your views here.
from rest_framework import status
from rest_framework.response import Response
from rest_framework.viewsets import ViewSet

from users.models import UserCart, User


class UserCartDeleteAPIView(ViewSet):
    def del_cart(self,request):
        """从购物车中删除商品"""
        id = request.query_params.get("id")
        try:
            UserCart.objects.filter(id=id).update(is_delete=True)
        except UserCart.DoesNotExist:
            return Response({"message":"参数有误"}, status=status.HTTP_400_BAD_REQUEST)

        return Response({"message":"删除商品成功"})

    def you_money(self,request):
        """从购物车中删除商品"""
        id = request.query_params.get("id")
        jine = request.query_params.get("jine")
        try:
            User.objects.filter(id=id).update(youMoney = jine )
        except User.DoesNotExist:
            return Response({"message":"参数有误"}, status=status.HTTP_400_BAD_REQUEST)

        return Response({"message":"删除商品成功"})


